<template>
  <div class="">
    <my-header>
      <span>{{ name }}</span>
    </my-header>
    <h1>这是商家列表页</h1>
    <my-item
      v-for="item in list"
      :key="item.id"
      :item="item"
      @click="$router.push('/detail/' + item.id)"
    ></my-item>

    <van-tabbar route>
      <van-tabbar-item icon="home-o" to="/about">列表页</van-tabbar-item>
      <van-tabbar-item icon="search" to="/">搜索</van-tabbar-item>
      <van-tabbar-item icon="friends-o">标签</van-tabbar-item>
      <van-tabbar-item icon="setting-o">标签</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
import myHeader from "../components/myHeader.vue";
import { getList } from "../utils/ele";
import myItem from "../components/myItem.vue";
export default {
  setup(props, ctx) {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    let name = route.query.name;
    let latitude = route.query.latitude;
    let longitude = route.query.longitude;
    const data = reactive({
      list: [],
    });
    getList({ latitude, longitude }).then((res) => {
      console.log(res);
      data.list = res;
    });

    return { ...toRefs(data), name };
    //在模版中用name所以要return出去 但是经纬度只在setup中用所以不用return
  },
  components: {
    myHeader,
    myItem,
  },
};
</script>

<style lang="scss"></style>
